<extend name="Layout:default"/>
<block name="title"><title>重设密码</title></block>
<block name="style">
<css href="/Public/Assets/Hui/lib/validator/jquery.validator.css"/>
<css href="/Public/Assets/Hui/lib/icheck/icheck.css"/>
<style>

</style>
</block>

<block name="main">
<div class="container clearfix">
	<div id="content-container">
		<div class="login-section" id="tab_register" class="HuiTab">
			  <div class="login-tab2 cl">重设密码</div>
			  <div class="login-tab3 cl"><a href="javascript:;" class="active">手机号码</a><a href="{:U('emailforpwd')}">邮箱设置</a></div>
			  <div class="login-con">
			  <form action="{:U('resetpwd_post')}" method="post" class="validator_form">
			  	<div class="control-group mb-20">
			  		<label class="formlabel" for="">手机号码</label>
					<div class="formControls">
						<input type="text" class="input-text radius  size-L" value="" placeholder="手机号码"  name="mobile" data-rule="required; mobile; remote[/users/login/checkhas/t/mobile]" data-msg-required="请输入手机号码" data-rule-mobile="[/^(((13[0-9]{1})|(15[0-35-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/,'请输入正确的手机号码']">
					</div>
			  	</div>
			  	<div class="control-group mb-20">
			  		<label class="formlabel" for="">新的密码</label>
					<div class="formControls">
						<input type="password" class="input-text radius  size-L" value="" placeholder="新的密码"  name="pwd" data-rule="密码:required;password;" data-msg-required="请输入新的密码">
					</div>
			  	</div>
			  	<div class="control-group mb-20">
			  		<label class="formlabel" for="">确认密码</label>
					<div class="formControls">
						<input type="password" class="input-text radius  size-L" value="" placeholder="再输一次新的密码"  name="repwd" data-rule="确认密码:required;match(pwd)" data-msg-required="请再输入一次新的密码">
					</div>
					
			  	</div>
				<div class="control-group mb-30">
			  		<label class="formlabel" for="">短信验证码</label>
					<div class="formControls row cl">
						<div class="col-7"><input type="text" class="input-text radius  size-L" value="" placeholder="填写你的短信验证码"  name="sms_code" data-rule="required;" data-msg-required="请输入短信验证码"></div>
						<div class="col-5" style="padding-left:20px;"><a  class="btn disabled btn-primary radius size-L" id="sendsms">获取验证码</a></div>
					</div>
			  	</div>
			  	<div class="control-group mb-40">
			  		<div class="formControls">
			  			<input class="btn btn-primary btn-block radius size-L" type="submit" id="resetpwd" value="重设密码">
			  		</div>
			  	</div>
			  </form>
			  <div class="mb-40"><a href="{:U('index')}">返回登录</a></div>
		</div>
		</div>
	</div>
</div>
<div id="codeModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <div class="modal-header">
    <h5 id="myModalLabel">请输入验证码</h5><a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();">×</a>
 </div>
 <div class="modal-body">
	<div class="row cl pt-10 pb-10">
		<div class="col-7 pos-r">
			<input type="text" class="input-text size-L" name="captcha_num" id="captcha_num" placeholder="验证码">
			<span class="n-msg n-error pos-a" style="margin-top:6px;display:none;" id="error">验证码错误</span>
		</div>
		<div class="col-5" style="padding-left:10px;">
			<img class="yanzheng_img" id="code_img" alt="" src="{:U('/users/verify/verify/id/resetpwd','l=4&fontsize=20&w=180&h=40')}"
			onclick="document.getElementById('code_img').src='{:U('/users/verify/verify/id/resetpwd','l=4&fontsize=20&w=180&h=40')}&time='+Math.random();"
			style="cursor: pointer;" title="点击获取"/>
		</div>
	</div>
 </div>
  <div class="modal-footer">
 	<button class="btn btn-primary" id="codesubmit">确定</button> <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
 </div>
</div>
</block>

<block name="script">
<js href="/Public/Assets/Hui/lib/validator/jquery.validator.js"/>
<js href="/Public/Assets/Hui/lib/validator/local/zh_CN.js"/>
<js href="/Public/Assets/Hui/lib/icheck/jquery.icheck.min.js"/>
<js href="/Public/Sea/modules/layer/2.1/layer/layer.js"/>
<js href="/Public/Assets/Hui/lib/bootstrap-modal/2.2.4/bootstrap-modalmanager.js"/>
<js href="/Public/Assets/Hui/lib/bootstrap-modal/2.2.4/bootstrap-modal.js"/>

<script>
$('input[name="mobile"]').on('valid.field', function(e, result, me){
	$("#sendsms").removeClass('disabled');
});
$('input[name="mobile"]').on('invalid.field', function(e, result, me){
	$("#sendsms").addClass('disabled');
});
$("#sendsms").on('click',function(){
	$("#captcha_num").val('');
	$("#code_img").trigger('click');
	$("#codeModal").modal("show");
	
})
$("#codesubmit").click(function(){
	var captcha_num = $("#captcha_num").val();
	$.post('/users/verify/verifycheck/id/resetpwd',{verify:captcha_num},function(data){
		if(data.ok){
			$("#codeModal").modal("hide");
			var mobile =  $('input[name="mobile"]').val();
			$.post('/users/login/sendsms',{mobile:mobile,type:'resetpwd'});
			settime('sendsms',60);
		}else{
			$("#error").show();
			$("#code_img").trigger('click');
		}
	});
})
$("#captcha_num").focus(function(){
	if($("#error").is(':visible')){
		$("#error").hide();
	}
})
function settime(obj,time){
	if (time == 0) { 
		$("#"+obj).removeClass("disabled").text("获取验证码");
		return;
	} else { 
		$("#"+obj).addClass('disabled').text("重新发送(" + time + ")"); 
		time--; 
	} 
	setTimeout(function() { 
		settime(obj,time) 
	},1000) 
}
$('.validator_form').validator({
		msgClass: "n-bottom", 
		msgIcon:"",
  	    valid: function(form){
  	    	var me = this;
  	    	//防止重复提交表单
  	        me.holdSubmit();
  	        var ii = layer.msg('数据处理中...', {icon: 16,time: 10000}, function(){
	    	    layer.alert('服务器响应超时', {icon: 7});
	    	});
  	     	$.ajax({
	            url:  $(form).attr('action'),
	            data: $(form).serialize(),
	            type: "POST",
	            dataType:"json",
	            success: function(data){
	            	layer.close(ii);
	            	//data = JSON.parse(data);  //str 转 json
	            	if (data.status==1) {
	            		layer.msg(data.info, {icon: 1,time:1000});
	                }else{
	                	layer.msg(data.info, {icon: 2,time:1000});
	                }
	            	//需要跳转的话
	            	if(data.url){
	                   	setTimeout(function(){
	                   		location.href= data.url;
	                   	},1000);
	                   }
	            	
	            	//信息提示框结束之后，表单可提交
	            	setTimeout(function(){
	            		me.holdSubmit(false);
	                 },1000);
	            	
	            }
        	});
  	   	}
});
</script>
</block>